package com.example.basic;

import java.util.ArrayList;

import android.content.Context;

public class Inventory {
  private static Inventory sInstance;

  public static Inventory getInstance(Context appContext) {
    if (null == sInstance) {
      sInstance = new Inventory(appContext);
    }
    return sInstance;
  }

  private final Context mAppContext;
  private final ArrayList<Product> mProducts;

  public Inventory(Context appContext) {
    mAppContext = appContext;

    mProducts = new ArrayList<Product>();
    for (int i=0; i<5; i++) {
      Product product = new Product(i);
      mProducts.add(product);
    }
  }

  public Product getProductById(int id) {
    for (Product p : mProducts) {
      if (id == p.getId()) {
        return p;
      }
    }
    return null;
  }

  public ArrayList<Product> getProducts() {
    return mProducts;
  }
}
